import Router from "vue-router";
import Vue from "vue";
Vue.use(Router);

const routes = [{
        path: "/",
        redirect: "/product",
    },
    {
        path: "/product",

        component: () => import("@/views/product/index.vue"),
        redirect: "/product/list",
        children: [{
                path: "list", // /product/list
                name: 'productList',
                component: () => import("@/views/product/children/list.vue"),
            },
            {
                path: "detail/:id", // /product/detail
                name: 'productDetail',
                component: () => import("@/views/product/children/detail.vue"),
            },
        ],
    },
    {
        path: "/cart",
        component: () => import("@/views/cart/index.vue")
    },
    {
        path: "/foo/:id/:name",
        name: 'FOO',
        component: () => import("@/views/foo/foo.vue")
    },
    {
        path: "/type",
        component: () => import("@/views/type/index.vue")
    },
    {
        path: "/my",
        component: () => import("@/views/my/index"),
        redirect: "/my/center",
        children: [{
                path: "center",
                component: () => import("@/views/my/children/center"),
            },
            {
                path: "set",
                component: () => import("@/views/my/children/set"),
            },
        ],
    },
    {
        path: "/order",
        component: () => import("@/views/order/index.vue"),
        children: [{
                path: "list",
                component: () => import("@/views/order/children/list")
            },
            {
                path: "submit", // 确认订单
                component: () => import("@/views/order/children/submit"),
            },
            {
                path: "detail",
                component: () => import("@/views/order/children/detail"),
            },
            {
                path: "pay",
                component: () => import("@/views/order/children/pay"),
            },
        ],
    },
    {
        path: "/login",
        component: () => import("@/views/account/index.vue")
    },
    {
        path: "/demo",
        component: () => import("@/views/demo/index.vue")
    },
];

const router = new Router({
    // hash模式, 带#号, history模式不带#号, history模式需要后端支持
    mode: 'history',
    scrollBehavior: () => ({
        y: 0
    }),
    routes,
});

export default router;